package com.cddx.logistics.controller;


import com.cddx.logistics.domain.dto.QueryDTO;
import com.cddx.logistics.domain.pojo.Department;
import com.cddx.logistics.service.DepartmentService;
import com.cddx.logistics.util.model.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/department")
@Api(tags = "部门管理")
public class DepartmentController {
    @Resource
    private DepartmentService departmentService;

    @PostMapping("/add")
    @ApiOperation("添加部门")
    public R addDepartment(@RequestBody Department department){
        return departmentService.addDepartment(department)?R.ok():R.error();
    }

    @PostMapping("/update")
    @ApiOperation("修改部门")
    public R updateDepartment(@RequestBody Department department){
        return departmentService.updateDepartment(department)?R.ok():R.error();
    }
    @GetMapping("/delete/{id}")
    @ApiOperation("删除部门")
    public R deleteDepartment(@PathVariable("id") Integer id){
        return departmentService.deleteDepartment(id)?R.ok():R.error();
    }
    @PostMapping("/queryPage")
    @ApiOperation("分页查询部门")
    public R queryPage(@RequestBody QueryDTO  department){
        return R.ok(departmentService.queryPage(department));
    }

    @GetMapping("/queryAll")
    @ApiOperation("查询所有部门 渲染下拉列表")
    public R queryAll(){
        return R.ok(departmentService.queryAll());
    }
    @PostMapping("/deleteIds")
    @ApiOperation("批量删除用户")
    public R deleteIds(@RequestBody Integer[] ids){
        return departmentService.deleteIds(ids)?R.ok():R.error("删除失败");
    }
}
